package uit.hcm.object;

import uit.bus.R;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;


public class ShowOverlay {

	private LinearLayout _bubbleLayout;
	private GeoPoint _point;
	private MapActivity _activity;

	public ShowOverlay(GeoPoint point, MapActivity activity) {
		this._point = point;
		this._activity = activity;
	}

	public boolean showView(final MapView mapView, String info) {

		
		// Get instance of the Bubble Layout ...
		LayoutInflater toristInfo = LayoutInflater.from(_activity);

		// _bubbleLayout = (LinearLayout) inflater.inflate(R.layout.bubble,
		// mapView, false);
		_bubbleLayout = (LinearLayout) toristInfo.inflate(R.layout.bubble,
				mapView, false);
		// .. configure its layout parameters
		MapView.LayoutParams params = new MapView.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, _point,
				MapView.LayoutParams.BOTTOM_CENTER);

		_bubbleLayout.setLayoutParams(params);

		// Locate the TextView
		TextView locationNameText = (TextView) _bubbleLayout
				.findViewById(R.id.locationName);

		// Set the Text
		locationNameText.setText(info);

		// Add the view to the Map
		mapView.addView(_bubbleLayout,0);
		mapView.setId(1);
		

		// Animate the map to center on the location
		mapView.getController().animateTo(_point);
		_bubbleLayout.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mapView.removeView(_bubbleLayout);
				mapView.setId(2);
			}
		});

		return true;

	};

}
